package personal.zq.practice.common.utils;

import net.sourceforge.pinyin4j.PinyinHelper;
import org.apache.commons.lang.StringUtils;

/**
 * @version V1.0
 * @PackageName: com.zhilingsd.cpic.marketing.business.common.utils
 * @ClassName: PinYinUtil
 * @Description:
 * @Author roxulo
 * @Date 2022/5/11
 */
public class PinYinUtil {

    /**
     * @Author roxulo
     * @Description 获取拼音首字母
     * @Date 2022/5/11 9:58
     * @param name
     * @return java.lang.String
     **/
    public static String getInitials(String name){
        //判空
        if(StringUtils.isBlank(name)){
            return "#";
        }
        String result = null;
       char word = name.charAt(0);
        String[] pinyinArray = PinyinHelper.toHanyuPinyinStringArray(word);
        if (pinyinArray != null) {
            result = String.valueOf(pinyinArray[0].charAt(0));
        } else {
            result = String.valueOf(word);
        }
        return result.toUpperCase();
    }
}
